#!/bin/bash
. initial
www=./www
apache(){
    if [ -z $APACHE_PID ]; then
	$www apache start
    fi
}
tomcat(){
    if [ -z $TOMCAT_PID ]; then
        $www tomcat start
    fi
}
dbconn(){
    if [ -z $DBCONN_ESTABLISHED ]; then
        $www restart

    fi

}

if [ $APACHE_TOMCAT_MONITOR = "YES" ]; then
    if [ -z $TOMCAT_PID ]; then
        $www tomcat start
    elif [ $TOMCAT_LISTEN_COUNT -lt 1 ]; then
	$www tomcat restart
    fi
    if [ -z $APACHE_PID ]; then
        $www apache start
    elif [ $APACHE_LISTEN_COUNT -lt 1 ]; then
	$www apache restart
    fi
    exit 1
fi

if [ $APACHE_MONITOR = "YES" ]; then
    apache
    exit 1
fi

if [ $TOMCAT_MONITOR = "YES" ]; then
    exit 1
    tomcat
fi

if [ $DBCONN_MONITOR = "YES" ]; then
    dbconn
fi

